<?php

namespace App\Observers;

use App\Models\lak\Residential;
use App\Utils\Lib\MyEs;
use Illuminate\Support\Facades\Log;
class ResidentialObserver
{
    /**
     * Handle the Residential "created" event.
     *
     * @param  \App\Models\lak\Residential  $residential
     * @return void
     */
    public function created(Residential $residential)
    {
        $es = new MyEs();

        try {
            //es添加
            $params = [
                'index' => $es->index,
                'id'    => $residential->id,
                'body'  => $residential->toArray()
            ];

            $res = $es->client->index($params);
            if ($res){
                Log::info($residential->id.'数据同步');
            }
        }catch (\Exception $exception){
            $redis = new \Redis();
            $redis->rPush($es->index,$es->type,$residential->id);
        }
    }

    /**
     * Handle the Residential "updated" event.
     *
     * @param  \App\Models\lak\Residential  $residential
     * @return void
     */
    public function updated(Residential $residential)
    {
        //
    }

    /**
     * Handle the Residential "deleted" event.
     *
     * @param  \App\Models\lak\Residential  $residential
     * @return void
     */
    public function deleted(Residential $residential)
    {
        //
    }

    /**
     * Handle the Residential "restored" event.
     *
     * @param  \App\Models\lak\Residential  $residential
     * @return void
     */
    public function restored(Residential $residential)
    {
        //
    }

    /**
     * Handle the Residential "force deleted" event.
     *
     * @param  \App\Models\lak\Residential  $residential
     * @return void
     */
    public function forceDeleted(Residential $residential)
    {
        //
    }
}
